package com.bjpowerrnode.javase.array.homework;
/*
酒店对象，酒店中右二维数组，二维数组模拟大厦。
 */
public class Hotel {
    private Room[][] rooms;

    //盖楼通过构造方法
    public Hotel(){
        this.rooms = new Room[3][10];
        //创建30个room对象
        for (int i = 0; i < rooms.length; i++) {//i是下标：0,1,2；i+1是楼层
            for (int j = 0; j < rooms[i].length; j++) {

                if(i == 0)rooms[i][j] = new Room((i+1)*100+j+1,"单人间",true);
                if(i == 1)rooms[i][j] = new Room((i+1)*100+j+1,"标准间",true);
                if(i == 2)rooms[i][j] = new Room((i+1)*100+j+1,"总统套房",true);
            }
        }
    }

    //在酒店对象上提供一个打印房间列表的方法
    public void print(){
        //打印所有房间状态就是遍历二位数组
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                System.out.print(rooms[i][j] + "");
                //输出引用时，会自动调用引用到的toString()方法
            }
            System.out.print("\n");
        }
    }

    //订房方法
    public void order(int roomNo){
       rooms[roomNo/100 -1][roomNo%100 -1].setStatus(false);
        System.out.println(roomNo + "订房成功！");
    }

    //退房方法
    public void exit(int roomNo){
        rooms[roomNo/100 -1][roomNo % 100 -1].setStatus(true);
        System.out.println(roomNo + "退房成功！");
    }

/*    //测试
    public static void main(String[] args) {
        //创建酒店对象
        Hotel hotel = new Hotel();

        //打印酒店房间状态
        hotel.print();
    }*/
}
